﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AbstractStudy
{
    // 设计模式：模板设计模式
    public abstract class Generator
    {
        public Generator() { }
        public Generator(string username, string pwd, string ip, string database)
        {
            DataBase = database;
            UserName = username;
            Pwd = pwd;
            IP = ip;
        }
        #region 公共属性
        public string DataBase { get; set; }
        public string UserName { get; set; }
        public string Pwd { get; set; } 
        public string IP { get; set; }
        #endregion

        #region 公共方法
        public virtual string Query()
        {
            return "生成查询数据库代码\n";
        }
        public virtual string Add()
        {
            return "生成添加数据库的代码\n";
        }
        public virtual string Update()
        {
            return "生成修改数据库的代码\n";
        }
        public virtual string Delete()
        {
            return "生成删除数据库的代码\n";
        }
        #endregion

        #region 抽象方法
        /// <summary>
        /// 分页代码
        /// </summary>
        /// <returns></returns>
        public abstract string PageList();
        /// <summary>
        /// 建立链接
        /// </summary>
        /// <returns></returns>
        public abstract string Connection(); 
        #endregion

        // 执行代码生成器
        public virtual string Execute()
        {
            string queryCode = Query();
            string addCode = Add();
            string updateCode = Update();
            string deleteCode = Delete();
            string pageListCode = PageList();
            string connectionCode = Connection();

            StringBuilder code = new StringBuilder();
            code.Append(queryCode)
                .Append(addCode)
                .Append(updateCode)
                .Append(deleteCode)
                .Append(pageListCode)
                .Append(connectionCode);
            return code.ToString();
        }
    }
}
